﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectStorageLib.Project;

public partial class User_EditProject : System.Web.UI.Page
{
    ProjectManager manager;
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        m_ctrlEditProject.Cancel += new EventHandler(ProjectCancel);
        m_ctrlEditProject.Saved += new EventHandler(ProjectSaved);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        String id = Request["id"];
        if (!String.IsNullOrWhiteSpace(id))
        {
            manager = new ProjectManager(Decimal.Parse(id, System.Globalization.CultureInfo.InvariantCulture));
            m_ctrlEditProject.Edit = true;
        }
        else
        {
            manager = ProjectManager.CreateNewAndGetProject(Security.GetCurrentUserID());

        }
       
        
        this.m_ctrlEditProject.ProjectManager = manager;
    }

    protected override void OnPreRender(EventArgs e)
    {
        this.DataBind();
        base.OnPreRender(e);
    }

    protected void ProjectSaved(Object snd, EventArgs e)
    {
        Server.Transfer("~/User/MyProjects.aspx");
    }
    protected void ProjectCancel(Object snd, EventArgs e)
    {
        Server.Transfer("~/User/MyProjects.aspx");
    }
}